/*
 * Main.cpp
 *
 *  Created on: 31/01/2014
 *      Author: Bruno
 */

#include "SortedBuffer.h"
#include <stdlib.h>
#include <iostream>
#include "DppmBuffer.h"
#include "TestDppmProcess.h"

void stress1() {

	int * tr = new int[10];
	for (int i = 0; i < 10; i++)
		tr[i] = i;

	for (int k = 0; k < 1000000; k++) {
		cout << k << endl;
		SortedBuffer * sq = new SortedBuffer();
		Tuple * T = new Tuple(10);
		for (int i = 0; i < 10; i++) {
			T->lastAct(i);
			sq->push(T->copy());
		}

		delete T;
		delete sq;
	}
	delete[] tr;
}

void stress2() {


	for (int k = 0; k < 1000; k++) {

		cout << k << endl;

		SortedBuffer* sq = new SortedBuffer();

		Tuple * T = new Tuple(10);

		for (int l = 0; l < 1000; l++) {
			cout << "        " << l << endl;


			for (int i = 0; i < 100; i++) {
				T->lastAct(i);
				sq->push(T->copy());
			}

			Tuple * T2;

			for (int i = 0; i < 100; i++) {
				T2 = sq->pop();
				delete T2;
			}

		}

		delete T;
		delete sq;
	}

}

void prueba1();

void stress3() {

	for (int i = 0; i < 100000; i++) {
		prueba1();
	}
	cout << "END stress3" << endl;
}

void prueba1() {

	SortedBuffer * sq = new SortedBuffer();
	Tuple * T = new Tuple(10);
	for (int i = 0; i < 10; i++){
		T->modes(i,i);
		T->sigAct();
	}

	for (int i = 0; i < 10; i++) {
		T->lastAct(i % 7);
		sq->push(T->copy());
	}

	sq->print();
	cout << "################" << endl;
	Tuple* T2;
	for (int i = 0; i < 10; i++) {
		T2 = sq->pop();
		delete T2;
	}
	sq->print();
	cout << "################" << endl;
	for (int i = 0; i < 10; i++) {
		T->lastAct(i % 7);
		sq->push(T->copy());
	}
	sq->clean();
	for (int i = 0; i < 10; i++) {
		T->lastAct(i % 7);
		sq->push(T->copy());
	}
	delete T;
	delete sq;
}

int main(int argc, char** argv) {

	cout << endl << "BEGIN" << endl;
	for(int k = 0; k < 10000000; k++){
		cout<<k<<endl;
		//cout << endl << "BEGIN" << endl;

		DppmBuffer dppmBuff;
		DppmParams * dppm = NULL;
		initDppm(dppm, dppmBuff);
		//Print(dppm);
		//FreeMemory(dppm);
		//return 0;

		Tuple * sol = NULL;
		doBacktracking(*dppm, dppmBuff, sol);
		//cout << "solucion: ";
		if (sol != NULL) {
////			for (int i = 0; i <= sol->lastAct(); i++) {
////				cout << "|" << sol->modes(i);
////			}
////			cout << endl;
////			cout << "time: " << sol->times(sol->lastAct()) << endl;
////			cout << "cost: " << sol->cost() << endl;
////
			delete sol;
		}
//		else{
//			cout<<"NO HAY SOLUCION!!"<<endl;
//		}
		delete dppm;


	}
	cout << "END" << endl;
	return 0;

}

